import { COORD_TYPE } from './_constants'

/**
 * 创建图片标签
 * @param {object | Array<object>} img
 * @param {COORD_TYPE} coordType
 * @returns
 */
export function ShowImageLabel(img, coordType) {
  return new Promise((resolve, reject) => {
    const imgs = Array.isArray(img) ? img : [img]

    window.AC.ImageLabel.create(imgs, coordType, {
      callbackFn: ({ result }) => {
        if (result === 0) {
          resolve()
        } else {
          reject()
        }
      }
    })
  })
}

/**
 * 根据图片标签ID定位到图片标签
 * @param {String | Array<String>} id
 * @param {Object} param
 * @returns
 */
export function FocusImageLabel(id, { distance, flytime = 10 } = {}) {
  return new Promise((resolve, reject) => {
    const ids = Array.isArray(id) ? id : [id]
    window.AC.ImageLabel.focus({
      ids,
      // 不传distance参数，默认定位到最佳视角
      distance,
      flytime,
      callbackFn: ({ result }) => {
        if (result === 0) {
          resolve()
        } else {
          reject()
        }
      }
    })
  })
}

/**
 * 根据图片标签ID删除图片标签
 * @param {String | Array<String>} id 图片id
 * @returns
 */
export function DeleteImageLabel(id) {
  return new Promise((resolve, reject) => {
    const ids = Array.isArray(id) ? id : [id]
    window.AC.ImageLabel.delete(ids, {
      callbackFn: ({ result }) => {
        if (result === 0) {
          resolve()
        } else {
          reject()
        }
      }
    })
  })
}

/**
 * 清除所有图片标签
 * @returns
 */
export function ClearImageLabel() {
  window.AC.ImageLabel.clear()
}
